
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class RoadMap {

	private int x;
	private int y;
	private int child_id;
	private String build_name;
	private int direction; // 0 is for building 1 is east 2 is west 3 is south 4 is north 5 is intersection
	private String type;
	Color color = null;
	BufferedImage image;
	
	public RoadMap (int __child_id) {
		this.child_id = __child_id;
		
		if (child_id < 0) {
			type = "user";
			color = new Color(0, 0, 0);

			this.image = this.setImage(child_id);
		}
		else if (child_id >= 0 && child_id < 100) {
			type = "space";
			color = new Color(224, 238, 238);
			
			this.image = this.setImage(child_id);
		}
		else if (child_id >= 100 && child_id < 200) {
			type = "road";
			color = new Color(255, 165, 79);
			
			this.image = this.setImage(child_id);
		}
		else if (child_id >= 200 && child_id < 300) {
			type = "building";
			color = new Color(189, 189, 189);

			this.image = this.setImage(child_id);
		}
	}
	
	public void setXY (int x, int y) {
		assert((0<=x && x<=15) && (0<=y && y<=15));
		this.x = x;
		this.y = y;
	}
	
	public void setChild_id(int cid)
	{
		this.child_id=cid;
	}

	public void setBuildName(String name) {
		this.build_name = name;
	}

	public String getBuildName() {
		return build_name;
	}
	
	public int[] getXY () {
		int[] position = new int[2];
		
		position[0] = this.x;
		position[1] = this.y;
		
		return position;
	}
	
	private BufferedImage setImage(int imagetype) {
		BufferedImage __image = null;		
		File path = null;
		
		if (imagetype >= 0 && imagetype < 100) {
			path = new File("images/walk.png");
		}
//		else if (imagetype >= 100 && imagetype < 200) {
//			path = new File("images/road.png");
//		}

		switch(imagetype) {
			case -1:
				path = new File("images/me_road_leftright.png");
				break;
			case -2:
				path = new File("images/me_road_updown.png");
				break;
			case -3:
				path = new File("images/me_road_rightdown.png");
				break;
			case -4:
				path = new File("images/me_road_leftdown.png");
				break;
			case -5:
				path = new File("images/me_road_leftup.png");
				break;
			case -6:
				path = new File("images/me_road_rightup.png");
				break;
			case 100:
				path = new File("images/road_leftright.png");
				break;
			case 101:
				path = new File("images/road_updown.png");
				break;
			case 102:
				path = new File("images/road_rightdown.png");
				break;
			case 103:
				path = new File("images/road_leftdown.png");
				break;
			case 104:
				path = new File("images/road_leftup.png");
				break;
			case 105:
				path = new File("images/road_rightup.png");
				break;
			case 200:
				path = new File("images/map_bus.png");
				break;
			case 201:
				path = new File("images/map_restaurant.png");
				break;
			case 202:
				path = new File("images/map_cafe.png");
				break;
			case 203:
				path = new File("images/map_house.png");
				break;
			case 204:
				path = new File("images/map_hospital.png");
				break;
			case 205:
				path = new File("images/map_bank.png");
				break;
			case 206:
				path = new File("images/map_parking.png");
				break;
			case 207:
				path = new File("images/map_gas.png");
				break;
			case 208:
				path = new File("images/map_mart.png");
				break;
			case 209:
				path = new File("images/map_conv.png");
				break;
			case 210:
				path = new File("images/map_place.png");
				break;
			case 211:
				path = new File("images/map_cinema.png");
				break;
			case 212:
				path = new File("images/map_gym.png");
				break;
			case 213:
				path = new File("images/map_gover.png");
				break;
			case 214:
				path = new File("images/map_church.png");
				break;
			case 215:
				path = new File("images/map_apart.png");
				break;
			case 216:
				path = new File("images/map_company.png");
				break;
			case 217:
				path = new File("images/map_school.png");
				break;
			case 299:
				path = new File("images/map_building.png");
				break;
			default:
				break;
		}
		
		if (path != null) {
			try {
				__image = ImageIO.read(path);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}			
		}
				
		return __image;
	}
	
	public int getChildId () {
		return child_id;
	}
	
	public Color getColor() {
		return color;
	}
	
	public String getType() {
		return type;
	}
	
	public BufferedImage getImage() {
		return image;
	}

	public int getDirection() {
		return direction;
	}

	public void setDirection(int direction) {
		this.direction = direction;
	}
}
